package com.sanji.pay.allinpay.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;

/**
 * extends 
 * AbstractWebSocketMessageBrokerConfigurer 
 * web socket config 
 * @author DELL
 *
 */
@Configuration
@EnableWebSocketMessageBroker  //1
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {

	@Override
	public void registerStompEndpoints(StompEndpointRegistry registry) { //2
		
		registry.addEndpoint("/api/endpointWisely").withSockJS();   //3注册广播
    registry.addEndpoint("/api/endpointChat").withSockJS();//注册一个STOMP 的endponit 点对点
	}

	@Override
	public void configureMessageBroker(MessageBrokerRegistry registry) { //4
		
//		registry.enableSimpleBroker("/topic");  //5
		registry.enableSimpleBroker("/api/queue","/api/topic");  //消息代理:queue-队列,topic-广播

	}
	
}

/*
 * 1 EnableWebSocketMessageBroker  开启stomp协议来传输基于代理的消息，控制器指出@MessageMapping,就像使用RequestMapping一样
 * 2 注册STOMP 协议的节点，（endponit） 并映射指定的URL
 * 3 注册一个STOMP 的endponit ，并指定使用SockJS 协议
 * 4 配置消息代理（Message  broken）
 * 5 广播式配置一个 /topic 消息代理
 */
